${page.setTitle("push-center| GOPS")}
<style type="text/css">
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .liger-button {
            margin-bottom: 3px;
        }
    
</style>
${token()}

<div class="body-pla-content">
  
    
 
    <form action="" method="post" id="classmsg" name="classmsg" >
     <table class="l-table-edit" id="msgTable">
     	<tr id="1">
     		    <td align="right" >发送时间：</td>
                <td align="left" >
						<input name="sendingTime" type="text" id="sendingTime"  style="width: 200px" />
				</td>
     	</tr>
       <tr id="2">
	       <td >发送到组：</td>
	       <td align="left">
	       		<input name="classCode" type="hidden" id="classCode" value=""  style="width: 200px"/>
				<input name="" type="text" id="className" value=""  />
	       </td>
       </tr>
       <tr id="3">
                <td align="right" >域编号：</td>
                <td align="left" >
						<input name="" type="text" id="domainName" value=""  style="width: 200px"/>
						<input name="domainCode" type="hidden" id="domainCode" value=""  />
				</td>
	   </tr> 
	    <tr id="4">
                <td align="right" >模板编号：</td>
                <td align="left" >
						<input name="" type="text" id="templateName" value=""  style="width: 200px"/>
						<input name="templateCode" type="hidden" id="templateCode" value="" />
				</td>
		</tr>
       
      </table>
      	
    </form> 
    
    <input type="button" value="发布消息" class="l-button l-button-submit"  onclick="doSubmit()" />
    
    
</div>



<script type="text/javascript">

 
$("#sendingTime").ligerDateEditor();

function doSubmit(){
		
		var classCode=$("#classCode").val();
		var title=$("#title").val();
		tr_id = $("#msgTable>tbody>tr:last").attr("id"); 
		
		//check dynamic tds
		for(var i=5;i<=tr_id;i++){
			var tds=$("#"+i).children().eq(1).find("textarea").val();
			if($.trim(tds)==''){
				$.ligerDialog.error('请检查必填值!');
				return;
			}
		}
		
		//var tds=$("#5").children().eq(1).find("textarea").val();
		//alert(tds);
		var queryString = $('#classmsg').serializeArray(); 
	    $.ajax({
	        url: "${appServer}/classmsg/add.json",   
	        data: queryString, 
	        type: "POST",
	        success: function(result) {
	        	if(result.hasError) {
					$.ligerDialog.error(result.message);
	        	}else{
	        		$.ligerDialog.success(result.message);
	        		parent.window.search();
	        		parent.$.ligerDialog.close();
	        		parent.$.ligerDialog.hide();
	        	}
	        }
	    });	
		return true;
}




	//-----------------------------------class start------------------
  $(function ()
        { 
            $("#className").ligerComboBox({
                onBeforeOpen: f_selectContact,width:200
            });
        });
        function f_selectContact()
        {
            $.ligerDialog.open({ 
            	title: ' 请选择用户分组', 
            	name:'winselector',
            	width: 700, 
            	height: 500,  
            	url: '${appServer}/class/list-allclass', 
            	buttons: [
                	{ text: '确定', onclick: f_selectContactOK },
                	{ text: '取消', onclick: f_selectContactCancel }
            	]
            });
            return false;
        }
        function f_selectContactOK(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择行!');
                return;
            }
            $("#classCode").val(data.code);
            $("#className").val(data.name);
            dialog.close();
        }
        function f_selectContactCancel(item, dialog)
        {
            dialog.close();
        }
		//-----------------------------------class end------------------
		
		//-----------------------------------template start------------------
  $(function ()
        { 
            $("#templateName").ligerComboBox({
                onBeforeOpen: f_selectContact2,width:200
            });
        });
        function f_selectContact2()
        {
            $.ligerDialog.open({ 
            	title: ' 请选择模板', 
            	name:'winselector',
            	width: 700, 
            	height: 500,  
            	url: '${appServer}/template/list-alltemplate', 
            	buttons: [
                	{ text: '确定', onclick: f_selectContactOK2 },
                	{ text: '取消', onclick: f_selectContactCancel2 }
            	]
            });
            return false;
        }
        function f_selectContactOK2(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择行!');
                return;
            }
            $("#templateCode").val(data.code);
            $("#templateName").val(data.title);
            deltr();
            addtr("msgTable",data.params,data.descr);
            dialog.close();
        }
        function f_selectContactCancel2(item, dialog)
        {
            dialog.close();
        }
        function addtr(id,params,descs){ 
	        var paramArray=new Array();
	        var descArray=new Array();
	        
	        paramArray=params.split(",");
	        if(!isNull(descs)){
	        	descArray=descs.split(",");
	        }
			tr_id = $("#msgTable>tbody>tr:last").attr("id"); 
			tr_id++; 
			var str="";
			for(var i=0;i<paramArray.length;i++){
				var dd=descArray[i];
				 if(isNull(dd)){
				 	dd=paramArray[i];
				 }
			//	str += "<tr id = '"+tr_id+"'><td  align='right'>"+dd.substring(0,9)+" : </td><td align='left'><input type='text' name='"+paramArray[i]+"' placeholder='"+paramArray[i]+"[必填]"+"' class='required'/></td></tr>"; 
				str += "<tr id = '"+tr_id+"'><td  align='right'>"+dd.substring(0,9)+" : </td><td align='left'><textarea rows='5' cols='35' name='"+paramArray[i]+"'  placeholder='"+paramArray[i]+"[必填]"+"'></textarea></td></tr>";
				tr_id++; 
			}
			$('#'+id).append(str); 
		 } 
		 function deltr(){
		 	var tr_id=$("#msgTable>tbody>tr:last").attr("id"); 
		 	for(var i=tr_id;i>4;i--){
		 		$('#'+i).remove(); 
		 	}
		 }
		 function isNull(send){
		 	if(send=='' || send==undefined || send==null){
 				return true;
			}
			return false;
		 }
		//-----------------------------------template end------------------
		
		//-----------------------------------domain start------------------
  $(function ()
        { 
            $("#domainName").ligerComboBox({
                onBeforeOpen: f_selectContact3,width:200
            });
        });
        function f_selectContact3()
        {
            $.ligerDialog.open({ 
            	title: ' 请选择域', 
            	name:'winselector',
            	width: 700, 
            	height: 500,  
            	url: '${appServer}/domain/listall-domain', 
            	buttons: [
                	{ text: '确定', onclick: f_selectContactOK3 },
                	{ text: '取消', onclick: f_selectContactCancel3 }
            	]
            });
            return false;
        }
        function f_selectContactOK3(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择行!');
                return;
            }
            $("#domainCode").val(data.code);
            $("#domainName").val(data.name);
            dialog.close();
        }
        function f_selectContactCancel3(item, dialog)
        {
            dialog.close();
        }
		//-----------------------------------domain end------------------
</script>